import 'package:flutter/material.dart';
import 'package:flutter_base/18_name_route/fourthPage.dart';
import 'package:flutter_base/18_name_route/secondPage.dart';
import 'package:flutter_base/18_name_route/thirdPage.dart';

abstract class RoutePages {
  static const fristPageRoute = '/fristPage';

  static const secondPageRoute = '/secondPage';

  static const thirdPageRoute = '/thirdPage';

  static const fourthPageRoute = '/fourthPage';
}

var routes = {
  RoutePages.secondPageRoute: (context, {mymodel}) => SecondPage(
        mymodel: mymodel,
      ),
  RoutePages.thirdPageRoute: (context) => const ThirdPage(),
  RoutePages.fourthPageRoute: (context, {arguement}) => const FourthPage(),
};

var onGenerateRoute = (RouteSettings setting) {
  final String? name = setting.name;
  final Function? pageRouteBuilder = routes[name];
  if (pageRouteBuilder != null) {
    if (setting.arguments != null) {
      print(setting.arguments);
      print('有参数');
      final Route route = MaterialPageRoute(builder: (context) {
        return pageRouteBuilder(context, mymodel: setting.arguments);
      });
      return route;
    } else {
      final Route route = MaterialPageRoute(builder: (context) {
        return pageRouteBuilder(context);
      });
      print('五参数');
      return route;
    }
  }
  return null;
};
